﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace eCompany.Custom_Controls
{
    public partial class small_raw_ctrl : UserControl
    {
        public eObj.material_type_enum rawType;
        public eObj.company_type_enum compType;
        public bool isRaw = false;
        public delegate void validateCaller();
        private validateCaller m_validCaller=null;

        public small_raw_ctrl(validateCaller validCaller,eObj.material_type_enum raw_type)
        {
            InitializeComponent();
            m_validCaller = validCaller;
            rawType = raw_type;
            pictTypePB.Image = Tools.GetRawTypeImage(rawType);
            nameLbl.Text = "Raw " + rawType.ToString();
            isRaw = true;
            valueTxt.Text = "0";
        }
        public small_raw_ctrl(validateCaller validCaller, eObj.company_type_enum comp_type)
        {
            InitializeComponent();
            compType = comp_type;
            pictTypePB.Image = Tools.GetCompanyTypeImage(compType);
            nameLbl.Text = compType.ToString();
            isRaw = false;
            valueTxt.Text = "0";

            //Setting Callback at end of constructor to not fire method while init of values
            m_validCaller = validCaller;
        }

        public double getValue()
        {
            System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");

            string str = valueTxt.Text;
            str = str.Replace(",", ".");
            if (str == "") str = "0";
            double val = 0;
            if (double.TryParse(str, System.Globalization.NumberStyles.AllowDecimalPoint, culture, out val) == true)
                return val;
            else
                return double.NaN;
        }
        public void setValue(double val)
        {
            valueTxt.Text = val.ToString("F2");
        }

        private void valueTxt_TextChanged(object sender, EventArgs e)
        {
            if(m_validCaller != null)
                this.m_validCaller();
        }
    }
}
